<%--
  Created by IntelliJ IDEA.
  User: chen
  Date: 29/03/2018
  Time: 1:25 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.sql.*" contentType="text/html;charset=utf-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>


    <title>检验注册页面</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

</head>

<body>
<br>
<%
    request.setCharacterEncoding("utf-8");
    String users=request.getParameter("username");
    String pass=request.getParameter("pwd");
%>
<%
    String driver = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/resemblance";
    String use = "root";
    String password = "12345678c";
    Class.forName(driver);
    Connection conn= DriverManager.getConnection(url,use,password);
    Statement stmt=conn.createStatement();
    if(stmt.executeQuery("SELECT * FROM user WHERE username='" + users + "'").next()){ %>
        <script type="text/JavaScript">
            alert("账号已经存在");
            window.history.back(-1);
        </script>
    <% }
    else{
        PreparedStatement sql =conn.prepareStatement("insert into user(username,password)values(?,?)");
        sql.setString(1,users);
        sql.setString(2,pass);
        int rtn=sql.executeUpdate();
        sql.close();
        conn.close();%>
        <jsp:forward page="login.jsp"/><%
    }
%>
</body>
</html>